﻿Public Class FloFauRelev2


    Dim db As New Connexion
    Dim Entrer, EntrerRes, Action, ActiveEsp, Selection As String
    Dim nomSite As String = ""
    Private idRecencement As Integer
    Public databaseName As String
    Private Sub FloFauRelev2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Me.Dispose()
    End Sub
    Private Sub ButtonAnnuler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAnnulerRec.Click
        Me.Close()
    End Sub
    Private Sub FloFauRelev2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ComboBoxIdEsp.Visible = False
        Me.ComboBoxCodeStade.Visible = False
        Me.ComboBoxCodeSite.Visible = False
        Me.ComboBoxCodeTyp.Visible = False
        Me.ComboBoxCodeTyp1.Visible = False


        Me.ButtonReslt.Visible = True
        Me.Height = 498
        SelecRech()
        majRech()
    End Sub

    Private Sub ButtonInclObs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonInclObs.Click
        Dim IntImpObs As New ImporterObserRec
        IntImpObs.idRec = idRecencement
        IntImpObs.Visible = True
        majObsr()
    End Sub
    Private Sub majObsr()
        Try
            db.myReq = "SELECT * FROM  [dbo].[GroupeAuteur] W INNER JOIN  [SILM].[dbo].[FloFauAuteur] S ON W.Id_Obs=S.Id_Obs where [Id_Rel]='" & idRecencement & "'"
            db.Connecter(databaseName)
            Me.ComboBoxObs.Items.Clear()
            While db.rdr.Read()
                Me.ComboBoxObs.Items.Add(db.rdr(3))
            End While
            db.Disconnecter()

        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub

    Private Sub SelecRech()
        Try
            db.myReq = "SELECT * FROM  [dbo].[FloFauRelTyp]"
            db.Connecter(databaseName)
            Me.ComboBoxCodeTyp.Items.Clear()
            Me.ComboBoxNomTyp.Items.Clear()
            Me.ComboBoxCodeTyp.Items.Add("")
            Me.ComboBoxNomTyp.Items.Add("Tous")

            Me.ComboBoxCodeTyp1.Items.Clear()
            Me.ComboBoxNomTyp1.Items.Clear()
            Me.ComboBoxCodeTyp1.Items.Add("")
            Me.ComboBoxNomTyp1.Items.Add("Tous")

            While db.rdr.Read()
                Me.ComboBoxCodeTyp1.Items.Add(db.rdr(0))
                Me.ComboBoxNomTyp1.Items.Add(db.rdr(2))
                Me.ComboBoxCodeTyp.Items.Add(db.rdr(0))
                Me.ComboBoxNomTyp.Items.Add(db.rdr(2))
            End While
            Me.ComboBoxCodeTyp.SelectedIndex = 0
            Me.ComboBoxNomTyp.SelectedIndex = 0
            Me.ComboBoxCodeTyp1.SelectedIndex = 0
            Me.ComboBoxNomTyp1.SelectedIndex = 0
            db.Disconnecter()

            db.myReq = "SELECT * FROM  [dbo].[Site]"
            db.Connecter(databaseName)
            Me.ComboBoxCodeSite.Items.Clear()
            Me.ComboBoxNomSite.Items.Clear()
            Me.ComboBoxCodeSite.Items.Add("")
            Me.ComboBoxNomSite.Items.Add("Tous")

            While db.rdr.Read()
                Me.ComboBoxCodeSite.Items.Add(db.rdr(0))
                Me.ComboBoxNomSite.Items.Add(db.rdr(9))
            End While
            Me.ComboBoxCodeSite.SelectedIndex = 0
            Me.ComboBoxNomSite.SelectedIndex = 0
            db.Disconnecter()


            db.myReq = "SELECT * FROM  [dbo].[Stade_Typ]"
            db.Connecter(databaseName)
            Me.ComboBoxNomStade.Items.Clear()
            Me.ComboBoxNomStade.Items.Clear()
            Me.ComboBoxCodeStade.Items.Add("")
            Me.ComboBoxNomStade.Items.Add("Tous")

            While db.rdr.Read()
                Me.ComboBoxCodeStade.Items.Add(db.rdr(0))
                Me.ComboBoxNomStade.Items.Add(db.rdr(2))

            End While
            Me.ComboBoxCodeStade.SelectedIndex = 0
            Me.ComboBoxNomStade.SelectedIndex = 0

            db.Disconnecter()

            db.myReq = "SELECT * FROM  [dbo].[FLOFAUSYST]"
            db.Connecter(databaseName)
            Me.ComboBoxNomEsp.Items.Clear()
            Me.ComboBoxNomEsp.Items.Clear()
            Me.ComboBoxIdEsp.Items.Clear()
            Me.ComboBoxCodeEsp.Items.Add("")
            Me.ComboBoxIdEsp.Items.Add("")
            Me.ComboBoxNomEsp.Items.Add("Tous")

            While db.rdr.Read()
                Me.ComboBoxCodeEsp.Items.Add(db.rdr(4))
                Me.ComboBoxNomEsp.Items.Add(db.rdr(14))
                Me.ComboBoxIdEsp.Items.Add(db.rdr(0))
            End While
            Me.ComboBoxCodeEsp.SelectedIndex = 0
            Me.ComboBoxNomEsp.SelectedIndex = 0
            Me.ComboBoxIdEsp.SelectedIndex = 0
            db.Disconnecter()

        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub

    Private Sub ComboBoxNomTyp_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomTyp.TextChanged

        If Me.ComboBoxNomTyp.FindString(Me.ComboBoxNomTyp.Text) > 0 Then
            Dim Pos As Int32 = Me.ComboBoxNomTyp.Text.Length
            Me.ComboBoxNomTyp.SelectedIndex = Me.ComboBoxNomTyp.FindString(Me.ComboBoxNomTyp.Text)
            Me.ComboBoxNomTyp.SelectionStart = Pos
            Me.ComboBoxNomTyp.SelectionLength = Me.ComboBoxNomTyp.Text.Length - Pos
            Me.ComboBoxCodeTyp.SelectedIndex = Me.ComboBoxNomTyp.FindString(Me.ComboBoxNomTyp.Text)
        Else
            Me.ComboBoxCodeTyp.Text = ""
        End If
    End Sub
    Private Sub ComboBoxNomTyp1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomTyp1.TextChanged

        If Me.ComboBoxNomTyp1.FindString(Me.ComboBoxNomTyp1.Text) > 0 Then
            Dim Pos As Int32 = Me.ComboBoxNomTyp1.Text.Length
            Me.ComboBoxNomTyp1.SelectedIndex = Me.ComboBoxNomTyp1.FindString(Me.ComboBoxNomTyp1.Text)
            Me.ComboBoxNomTyp1.SelectionStart = Pos
            Me.ComboBoxNomTyp1.SelectionLength = Me.ComboBoxNomTyp1.Text.Length - Pos
            Me.ComboBoxCodeTyp1.SelectedIndex = Me.ComboBoxNomTyp1.FindString(Me.ComboBoxNomTyp1.Text)
        Else
            Me.ComboBoxCodeTyp1.Text = ""
        End If
    End Sub

    Private Sub ComboBoxNomSite_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomSite.TextChanged

        If Me.ComboBoxNomSite.FindString(Me.ComboBoxNomSite.Text) > 0 Then
            Dim Pos As Int32 = Me.ComboBoxNomSite.Text.Length
            Me.ComboBoxNomSite.SelectedIndex = Me.ComboBoxNomSite.FindString(Me.ComboBoxNomSite.Text)
            Me.ComboBoxNomSite.SelectionStart = Pos
            Me.ComboBoxNomSite.SelectionLength = Me.ComboBoxNomSite.Text.Length - Pos
            Me.ComboBoxCodeSite.SelectedIndex = Me.ComboBoxNomSite.FindString(Me.ComboBoxNomSite.Text)
        Else
            Me.ComboBoxCodeSite.Text = ""
        End If
    End Sub

    Private Sub ComboBoxNomStade_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomStade.TextChanged

        If Me.ComboBoxNomStade.FindString(Me.ComboBoxNomStade.Text) > 0 Then
            Dim Pos As Int32 = Me.ComboBoxNomStade.Text.Length
            Me.ComboBoxNomStade.SelectedIndex = Me.ComboBoxNomStade.FindString(Me.ComboBoxNomStade.Text)
            Me.ComboBoxNomStade.SelectionStart = Pos
            Me.ComboBoxNomStade.SelectionLength = Me.ComboBoxNomStade.Text.Length - Pos
            Me.ComboBoxCodeStade.SelectedIndex = Me.ComboBoxNomStade.FindString(Me.ComboBoxNomStade.Text)
        Else
            Me.ComboBoxCodeStade.Text = ""
        End If
    End Sub

    Private Sub ComboBoxNomEsp_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomEsp.TextChanged

        ' If Me.ComboBoxNomEsp.FindString(Me.ComboBoxNomEsp.Text) > 0 Then
        Dim Pos As Int32 = Me.ComboBoxNomEsp.Text.Length
        Me.ComboBoxNomEsp.SelectedIndex = Me.ComboBoxNomEsp.FindString(Me.ComboBoxNomEsp.Text)
        Me.ComboBoxNomEsp.SelectionStart = Pos
        Me.ComboBoxNomEsp.SelectionLength = Me.ComboBoxNomEsp.Text.Length - Pos
        Me.ComboBoxCodeEsp.SelectedIndex = Me.ComboBoxNomEsp.FindString(Me.ComboBoxNomEsp.Text)
        Me.ComboBoxIdEsp.SelectedIndex = Me.ComboBoxNomEsp.FindString(Me.ComboBoxNomEsp.Text)
        'Else
        'Me.ComboBoxCodeEsp.Text = ""
        'Me.ComboBoxIdEsp.Text = ""
        'End If
    End Sub

    Private Sub ButtonRech_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonRech.Click
        Entrer = ""
        majRech()
    End Sub

    Private Sub majRech()
        If Me.ComboBoxNomSite.Text = "Tous" And Me.ComboBoxNomTyp.Text = "Tous" Then
            db.myReq = "SELECT * FROM  [dbo].[FloFauRelev2] W INNER JOIN   [dbo].[Site] S ON W.ID_Sit=S.ID_Sit"
            db.Connecter(databaseName)
            DataGridViewRec.Rows.Clear()
            Do While db.rdr.Read()
                DataGridViewRec.Rows.Add(db.rdr(0), db.rdr(1), db.rdr(2), db.rdr(3), db.rdr(4), db.rdr(5), db.rdr(6), db.rdr(7), db.rdr(8), db.rdr(9), db.rdr(10), db.rdr(20))
            Loop
            db.Disconnecter()
        ElseIf Me.ComboBoxNomSite.Text = "Tous" And Not ComboBoxNomTyp.Text = "Tous" Then
            db.myReq = "SELECT * FROM  [dbo].[FloFauRelev2] W INNER JOIN   [dbo].[Site] S ON W.ID_Sit=S.ID_Sit WHERE [Id_RTyp] ='" & Me.ComboBoxCodeTyp.SelectedItem & "'"
            db.Connecter(databaseName)
            DataGridViewRec.Rows.Clear()
            Do While db.rdr.Read()
                DataGridViewRec.Rows.Add(db.rdr(0), db.rdr(1), db.rdr(2), db.rdr(3), db.rdr(4), db.rdr(5), db.rdr(6), db.rdr(7), db.rdr(8), db.rdr(9), db.rdr(10), db.rdr(20))
            Loop
            db.Disconnecter()
        ElseIf ComboBoxNomTyp.Text = "Tous" And Not Me.ComboBoxNomSite.Text = "Tous" Then
            db.myReq = "SELECT * FROM  [dbo].[FloFauRelev2] W INNER JOIN   [dbo].[Site] S ON W.ID_Sit=S.ID_Sit WHERE [ID_Sit] ='" & Me.ComboBoxCodeSite.SelectedItem & "'"
            db.Connecter(databaseName)
            DataGridViewRec.Rows.Clear()
            Do While db.rdr.Read()
                DataGridViewRec.Rows.Add(db.rdr(0), db.rdr(1), db.rdr(2), db.rdr(3), db.rdr(4), db.rdr(5), db.rdr(6), db.rdr(7), db.rdr(8), db.rdr(9), db.rdr(10), db.rdr(20))
            Loop
            db.Disconnecter()
        ElseIf Not (Me.ComboBoxNomSite.Text = "Tous" And ComboBoxNomTyp.Text = "Tous") Then
            db.myReq = "SELECT * FROM  [dbo].[FloFauRelev2] W INNER JOIN   [dbo].[Site] S ON W.ID_Sit=S.ID_Sit WHERE [ID_Sit] ='" & Me.ComboBoxCodeSite.SelectedItem & "' and [Id_RTyp] ='" & Me.ComboBoxCodeTyp.SelectedItem & "'"
            db.Connecter(databaseName)
            DataGridViewRec.Rows.Clear()
            Do While db.rdr.Read()
                DataGridViewRec.Rows.Add(db.rdr(0), db.rdr(1), db.rdr(2), db.rdr(3), db.rdr(4), db.rdr(5), db.rdr(6), db.rdr(7), db.rdr(8), db.rdr(9), db.rdr(10), db.rdr(20))
            Loop
            db.Disconnecter()

        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim typ1 As New TypologieNiv1Form(databaseName)
        typ1.Text = "Type"
        typ1.Table = "FloFauRelTyp"
        typ1.Visible = True
        majRech()
    End Sub

    Private Sub button11_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNouvREc.Click
        Me.DateTimePickerHD.Text = ""
        Me.DateTimePickerHF.Text = ""
        Me.TextBoxInon.Text = ""
        Me.TextBoxTxtTempVis.Text = ""
        Me.RichTextBoxObs.Text = ""
        Action = "Ajouter"

    End Sub

    Private Sub DataGridViewRec_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridViewRec.CurrentCellChanged
        If Entrer = "debut" Then
            selectRec()
        End If
    End Sub
    Private Sub DataGridViewRec_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridViewRec.MouseClick
        If e.Button = MouseButtons.Left Then
            Entrer = "debut"
            selectRec()
        End If
    End Sub


    Private Sub selectRec()
        Try
            If Not DataGridViewRec.SelectedCells(0).ToString = "" Then
                Me.DateTimePickerDRec.Value = Me.DataGridViewRec.SelectedCells(3).Value
                Me.DateTimePickerHD.Value = Me.DataGridViewRec.SelectedCells(4).Value
                Me.DateTimePickerHF.Value = Me.DataGridViewRec.SelectedCells(5).Value
                Me.ComboBoxNomTyp1.SelectedIndex = Me.ComboBoxCodeTyp.Items.IndexOf(Me.DataGridViewRec.SelectedCells(2).Value)
                Me.TextBoxInon.Text = Me.DataGridViewRec.SelectedCells(7).Value
                Me.TextBoxTxtTempVis.Text = Me.DataGridViewRec.SelectedCells(6).Value
                Me.RichTextBoxObs.Text = Me.DataGridViewRec.SelectedCells(10).Value

                majResRec()
            End If
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub


    Private Sub ButtonNouvREc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNouvREc.Click

    End Sub

    Private Sub ButtonValider_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonValider.Click
        If Action = "Ajouter" Then

            '  db.myReq = " INSERT INTO  [ "  & databaseName & "].[dbo].[FloFauRelev2](ID_SIT,Id_RTyp,Date_Rel,HreDbt_Rel,HreFin_Rel,Srfce_Rel,Meteo_Rel ,SaisS_Rel,SaisA_Rel,Note_Rel) VALUES('" & db.idSite & "','" & Me.ComboBoxCodeTyp1.Text & "','" &  & "','" & Me.DateTimePickerHD.Text & "','" & (Me.DateTimePickerHF.Text) & "','" & Me.TextBoxTxtTempVis.Text & "','" & Me.TextBoxInon.Text & "','" & Date.Now.Date & "','0','" & Me.RichTextBoxObs.Text & "')"
            db.myReq = " INSERT INTO  [dbo].[FloFauRelev2](ID_SIT,Id_RTyp,Date_Rel,HreDbt_Rel,HreFin_Rel,Srfce_Rel,Meteo_Rel ,SaisS_Rel,SaisA_Rel,Note_Rel) VALUES('" & db.idSite & "','" & Me.ComboBoxCodeTyp1.Text & "','','" & Me.DateTimePickerHD.Text & "','" & Me.DateTimePickerHF.Text & "','" & Me.TextBoxTxtTempVis.Text & "','" & Me.TextBoxInon.Text & "','','0','" & Me.RichTextBoxObs.Text & "')"
            db.Connecter(databaseName)
            db.Disconnecter()
            db.myReq = "Select max([Id_Rel]) FROM  [dbo].[FloFauRelev2]"
            db.Connecter(databaseName)
            While db.rdr.Read()
                idRecencement = db.rdr(0)
            End While
            db.Disconnecter()
            MsgBox("Ajout effectuée avec succès")

        Else
            'db.myReq = " UPDATE  [ "  & databaseName & "].[dbo].[FloFauRelev2] SET [ID_SIT] ='" & db.idSite & "',[Id_RTyp] ='" & Me.ComboBoxCodeTyp1.Text & "', [Date_Rel] = '" & Me.DateTimePickerDRec.Text & "',[HreDbt_Rel] = '" & Me.DateTimePickerHD.Text & "',[HreFin_Rel] = '" & Me.DateTimePickerHF.Text & "',[Srfce_Rel] = '" & Me.TextBoxTxtTempVis.Text & "',[Meteo_Rel] = '" & Me.TextBoxInon.Text & "',[SaisS_Rel] = '" & Date.Now & "',[SaisA_Rel]='0',[Note_Rel] = '" & Me.RichTextBoxObs.Text & "' WHERE [Id_Rel]='" & Me.DataGridViewRec.SelectedCells(0).Value & "'"
            db.myReq = " UPDATE  [dbo].[FloFauRelev2] SET [ID_SIT] ='" & db.idSite & "',[Id_RTyp] ='" & Me.ComboBoxCodeTyp1.Text & "', [Date_Rel] = '',[HreDbt_Rel] = '" & Me.DateTimePickerHD.Text & "',[HreFin_Rel] = '" & Me.DateTimePickerHF.Text & "',[Srfce_Rel] = '" & Me.TextBoxTxtTempVis.Text & "',[Meteo_Rel] = '" & Me.TextBoxInon.Text & "',[SaisS_Rel] = '',[SaisA_Rel]='0',[Note_Rel] = '" & Me.RichTextBoxObs.Text & "' WHERE [Id_Rel]='" & Me.DataGridViewRec.SelectedCells(0).Value & "'"
            db.Connecter(databaseName)
            db.Disconnecter()
            MsgBox("Mise à jour effectuée avec succès")
            Entrer = ""
            majRech()
        End If
    End Sub

    Private Sub ButtonNouvTyp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNouvTyp.Click
        Dim typ1 As New TypologieNiv1Form(databaseName)
        typ1.Text = "Type"
        typ1.Table = "FloFauRelTyp"
        typ1.Visible = True
        majRech()
    End Sub

    Private Sub ButtonReslt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReslt.Click
        If Me.GroupBoxResultat.Visible = True Then
            Me.ButtonReslt.Visible = True
            Me.Height = 498
            Me.GroupBoxResultat.Visible = False
            Me.GroupBoxRenc.Enabled = True
            Me.GroupBoxButton.Enabled = True
            Me.GroupBoxSite.Enabled = True
            Me.GroupBoxType.Enabled = True
            Dim img1 As Image
            img1 = Image.FromFile("C:\Users\Altaf\Documents\Visual Studio 2010\Projects\SILM_V_06_2012\SILM_V_06_2012\images\down.png")
            Me.ButtonReslt.Image = img1
        Else
            Dim WidthEcr As String = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString()
            Dim HeightEcr As String = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString()
            If Me.Height > HeightEcr - 150 Then
                Me.Height = HeightEcr - 150
            End If
            If Me.Width > WidthEcr - 150 Then
                Me.Width = WidthEcr - 150
            End If
            'Me.ButtonReslt.Visible = False
            Me.Height = 717
            'Me.GroupBoxResultat.Top = 498
            Me.GroupBoxResultat.Visible = True
            Me.GroupBoxRenc.Enabled = False
            Me.GroupBoxButton.Enabled = False
            Me.GroupBoxSite.Enabled = False
            Me.GroupBoxType.Enabled = False
            Dim img1 As Image
            img1 = Image.FromFile("C:\Users\Altaf\Documents\Visual Studio 2010\Projects\SILM_V_06_2012\SILM_V_06_2012\images\up.png")
            Me.ButtonReslt.Image = img1
        End If
        Entrer = ""
    End Sub

    Private Sub majResRec()

        db.myReq = "Select *  from  [dbo].[FloFauRelEsp] Res INNER JOIN   [dbo].[FLOFAUSYST] W ON Res.Id_FloFauSyst=W.Id_FloFauSyst WHERE Res.[ID_Rel]=" & Me.DataGridViewRec.SelectedCells(0).Value
        db.Connecter(databaseName)
        DataGridViewResRec.Rows.Clear()
        Do While db.rdr.Read()
            Dim std As String = Me.ComboBoxNomStade.Items.Item(Me.ComboBoxCodeStade.Items.IndexOf(db.rdr(3)))
            DataGridViewResRec.Rows.Add(db.rdr(0), db.rdr(1), db.rdr(2), db.rdr(3), "", db.rdr(12), db.rdr(21), std, db.rdr(5), db.rdr(6))
        Loop
        db.Disconnecter()

    End Sub

    Private Sub DataGridViewResRec_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridViewResRec.CurrentCellChanged
        If EntrerRes = "debut" Then
            selectionResRec()
        End If
    End Sub
    Private Sub DataGridViewResRec_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridViewResRec.MouseClick
        If e.Button = MouseButtons.Left Then
            EntrerRes = "debut"
            selectionResRec()
        End If
    End Sub
    Private Sub selectionResRec()
        If EntrerRes = "debut" Then
            ActiveEsp = ""
            Me.ComboBoxNomStade.SelectedIndex = Me.ComboBoxCodeStade.Items.IndexOf(Me.DataGridViewResRec.SelectedCells(3).Value)
            Me.TextBoxEff.Text = Me.DataGridViewResRec.SelectedCells(8).Value
            'Me.ComboBoxCodeEsp.SelectedIndex = Me.ComboBoxCodeEsp.Items.IndexOf(Me.DataGridViewResRec.SelectedCells(2).Value)
            Me.ComboBoxNomEsp.SelectedIndex = Me.ComboBoxIdEsp.Items.IndexOf(Me.DataGridViewResRec.SelectedCells(2).Value)
            Me.RichTextBoxNote.Text = Me.DataGridViewResRec.SelectedCells(9).Value
            Me.LabelSaisie.Text = "Modifier"
            Action = "Modifier"
        End If
    End Sub

    Private Sub ButtonModResRec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonModResRec.Click
        Action = "Modifier"
        Me.LabelSaisie.Text = "Modifier"
    End Sub

    Private Sub ButtonSupResRec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSupResRec.Click
        If MessageBox.Show("Vous voulez vraiment supprimer ce résultat du recensement?", "Suppression", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            supprimerResRec()
        End If
    End Sub

    Private Sub ButtonSupRec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSupRec.Click
        If MessageBox.Show("Vous voulez vraiment supprimer ce recensement?", "Suppression", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            If MessageBox.Show("Si vous supprimez ce recensement ces résultats seront supprimer", "Confirmer la suppression", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                supprimerResRec()
                db.myReq = "DELETE FROM  [dbo].[FloFauRelev2] WHERE [Id_Rel]=" & Me.DataGridViewRec.SelectedCells(0).Value
                db.Connecter(databaseName)
                db.Disconnecter()
                MessageBox.Show("La suppression est fait!", "Supprimer")
                Entrer = ""
                majRech()
            End If
        End If

    End Sub

    Private Sub supprimerResRec()

        db.myReq = "DELETE FROM  [dbo].[FloFauRelEsp] WHERE [Id_REsp]=" & Me.DataGridViewResRec.SelectedCells(0).Value
        db.Connecter(databaseName)
        db.Disconnecter()
        MessageBox.Show("La suppression est fait!", "Supprimer")
        EntrerRes = ""
        majResRec()
    End Sub

    Private Sub ButtonNouvResRec_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNouvResRec.Click
        Action = "Ajouter"
        Me.RichTextBoxNote.Text = ""
        Me.TextBoxEff.Text = ""
        Me.ComboBoxCodeEsp.SelectedIndex = 1
        Me.ComboBoxNomEsp.SelectedIndex = 1
        Me.ComboBoxNomStade.SelectedIndex = 1
        Me.ComboBoxCodeStade.SelectedIndex = 1
        Me.LabelSaisie.Text = "Ajouter"
    End Sub

    Private Sub ButtonValiderRest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonValiderRest.Click
        If Action = "Ajouter" Then
            db.myReq = " INSERT INTO  [dbo].[FloFauRelEsp]([Id_Rel],[Id_FloFauSyst],[Id_StdTyp],[Stade_REsp],[Abond_REsp],[Note_REsp]) VALUES('" & Me.DataGridViewRec.SelectedCells(0).Value & "','" & Me.ComboBoxIdEsp.Text & "','" & Me.ComboBoxCodeStade.Text & "','','" & Me.TextBoxEff.Text & "','" & Me.RichTextBoxNote.Text & "')"
            db.Connecter(databaseName)
            db.Disconnecter()

            MsgBox("Ajout effectuée avec succès")
            majResRec()

        ElseIf Action = "Modifier" Then
            db.myReq = " UPDATE  [dbo].[FloFauRelEsp] SET [Id_Rel] ='" & Me.DataGridViewResRec.SelectedCells(1).Value & "',[Id_FloFauSyst] ='" & Me.ComboBoxIdEsp.Text & "', [Id_StdTyp] = '" & Me.ComboBoxCodeStade.Text & "',Stade_REsp='',[Abond_REsp] = '" & Me.TextBoxEff.Text & "',[Note_REsp] = '" & Me.RichTextBoxNote.Text & "' WHERE [Id_REsp]='" & Me.DataGridViewResRec.SelectedCells(0).Value & "'"
            MsgBox(db.myReq)
            db.Connecter(databaseName)
            db.Disconnecter()
            MsgBox("Mise à jour effectuée avec succès")
            EntrerRes = ""
            majResRec()
        End If
    End Sub

    Private Sub ButtonNouvStade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNouvStade.Click
        Dim typ1 As New TypologieNiv1Form(databaseName)
        typ1.Text = "Type"
        typ1.Table = "Stade_Typ"
        typ1.Visible = True
    End Sub
End Class